package mylab.starters.mybatis.support.foreignKey;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import mylab.base.model.entity.Entity;

@SuppressWarnings({"unchecked", "rawtypes"})
public interface ForeignKeyService {

    void register();

    default void checkOnDelete(String pkTable, Object id) throws ForeignKeyException {
        Assert.notNull(pkTable);
        TableInfo tableInfo = TableInfoHelper.getTableInfo(pkTable);
        Assert.notNull(tableInfo);
        checkOnDelete((Class<? extends Entity>) tableInfo.getEntityType(), id);
    }

    void checkOnDelete(Class<? extends Entity> pkEntityClass, Object pkValue) throws ForeignKeyException;
}
